package cn.yunyichina.provider.message.service.impl;

import cn.yunyichina.provider.iface.entity.common.Response;
import cn.yunyichina.provider.message.dao.TmpTemplateDao;
import cn.yunyichina.provider.message.entity.TmpTemplate;
import cn.yunyichina.utils.convert.JsonUtils;
import com.alibaba.druid.support.json.JSONUtils;
import lombok.extern.log4j.Log4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by zhuxp on 2017/11/10.
 *
 * @param
 * @Descrition
 */
@Service
@Log4j
public class TmpTemplateServiceImpl {

    @Autowired
    private TmpTemplateDao tmpTemplateDao;

    /**
     * yyt.message.tmp.template.get
     * @description 查询模板信息
     * @param data
     * @return
     */
    public Response getTmpTemplate(String data){
        Response response = new Response();
        try {
            TmpTemplate template = JsonUtils.parseObject(data,TmpTemplate.class);
            List<TmpTemplate> list = tmpTemplateDao.select(template);
            if(list.isEmpty()){
                response.setResultCodeAndMessage("-2","未查询到模板信息!");
                return  response;
            }
            response.setResultCodeAndMessageAndResult("0","查询模板成功",JsonUtils.toJsonString(list));
        }catch (Exception e){
            log.error("查询模板异常",e);
            response.setResultCodeAndMessage("-1","查询模板异常!");
        }
        return  response;
    }
}
